class Solution {//leetcode1218——最长对数子序列
public:
    int longestSubsequence(vector<int>& arr, int difference) {
        unordered_map<int,int> hash;
        int n=arr.size();
        int ret=1;
        hash[arr[0]]=1;
        for(int i=1;i<n;i++){
            int last=arr[i]-difference;
            if(hash.count(last)){
                hash[arr[i]]=hash[last]+1;
            }
            else{
                hash[arr[i]]=1;
            }
            ret=max(ret,hash[arr[i]]);
        }
        return ret;
    }
};